package com.xxl.job.admin.core.util;

import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

/**
 * @Author fanchunshuai
 * @Description sql session工具类
 * @Date 2023/3/15
 * @Version 1.0
 */
public class SqlSessionUtil {

    /**
     * 创建可批量执行的SqlSession对象
     * @return
     */
    public static SqlSession createSqlBatchSession(){
        SqlSessionFactory sqlSessionFactory = SpringApplicationContext.getBean(SqlSessionFactory.class);
        SqlSession session = sqlSessionFactory.openSession(ExecutorType.BATCH,false);
        return session;
    }


    public static void flush(SqlSession session){
        session.flushStatements();
        session.commit();
        session.close();
    }
}
